package com.zhiyou100.filter;

import java.io.IOException;
import java.net.Inet4Address;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListFilter implements Filter{

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		Object obj = request.getServletContext().getAttribute("BaseContext");
		if(obj == null) {
			String basePath = request.getScheme()+"://"+Inet4Address.getLocalHost().getHostAddress()+":"+request.getServerPort()+request.getContextPath()+"/";
			request.getServletContext().setAttribute("BaseContext", basePath);
			
		}
		chain.doFilter(request, resp);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}
	
}
